package IO.file;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class TextFile {
    public static void main(String[] args) {
        File f = new File("demo.txt");
        if (!f.exists()) {
            try {
                f.createNewFile();
                if (!f.canWrite()) {
                    f.setWritable(true);
                }
                FileWriter w = new FileWriter(f);
                w.write("hello");
                w.close();
                if (!f.canRead()) {
                    f.setReadable(true);
                }
                FileReader r = new FileReader(f);
                int c;
                while ((c = r.read()) != -1) {
                    System.out.println((char) c);
                }
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        f.delete();
    }
}
